package com.twu.biblioteca;

import java.util.Random;

/**
 * Created by thoughtworks on 4/8/14.
 */
public class Movie extends Item {
    private final String producer;
    private final String director;
    private final String yop;
    private final String name;
    private static int movieCount = 2001;
    private boolean available;
    private int movieId;
    private int rating;

    public Movie(String name, String producer, String director, String yop) {
        movieId = movieCount++;
        this.name = name;
        this.producer = producer;
        this.director = director;
        this.yop = yop;
        this.rating = (int) (Math.random() + 1);
        available = true;
    }

    public boolean isAvailable() {
        return available;
    }

    public String getName() {
        return name;
    }

    public boolean checkOut() {
        if(available) {
            available = false;
            return true;
        }
        return false;
    }

    public boolean checkIn() {
        if(!available)
        {
            available = true;
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return movieId + "\t" + name + "\t" + producer + "\t" + director + "\t" + yop + "\t" + rating;
    }

    @Override
    public boolean equals(Object obj) {
        Movie movie = (Movie) obj;
        if(this.name  == movie.name && this.producer  == movie.producer && this.director  == movie.director && this.yop  == movie.yop)
            return true;
        return false;
    }

}
